﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using TTGame;
using CinemaDirector;

/*
 * ForceMoveTrigger
 * 强制位移的触发器
 *
 * 给对象一个移动的指令。注意，该强制位移不会触发状态动画的配合，仅仅是强制位移。不过死亡状态还是不支持位移的。
 *
 *
 * 依赖：
 *
 * ！不写重复代码！
 * @author TTun
 * @date 8/2/2017 8:31:20 PM
 */
namespace TTGameEngine {
public enum MoveStrategy {
    Dir_CasterFace,      //施法者面向
    Dir_MuzzleForward,  //射击点位置.射击点“muzzle”
    Dir_SelectorDir,    //选择的方向
    Dir_TowardTargetObj,    //朝向选择的目标的方向
    Pos_SelectorPos,    //选择的坐标
    Pos_TargetObjPos,   //选择的目标
    Follow_TargetObj,   //跟随选择的目标

}
[CutsceneItemAttribute("LT Trigger", "LT ForceMove Trigger", CutsceneItemGenre.ActorItem)]
public class ForceMoveTrigger : CinemaActorEvent {

    public MoveStrategy forceMoveStrategy = MoveStrategy.Dir_CasterFace;
    public float moveSpeed = 1f;
    public float maxDistance = 0f;  // 0 表示不限制距离
    public float maxMoveTime = 0f;  // 0 表示不限制时间
    public int maxHarmCount = 1;   // 可伤害的人数。

    MoveInfo m_skillMoveInfo = new MoveInfo();
    Puppet obj = null;
    SkillTL skill = null;

    public override void Trigger(GameObject actor) {
#if UNITY_EDITOR
        if(Application.isPlaying == false) {
            return;
        }
#endif

        obj = actor.GetComponent<Puppet>();
        skill = this.GetSkill();
        Transform casterTF = actor.transform;

        Tools.SetMoveInfoOneTarget(m_skillMoveInfo, forceMoveStrategy, moveSpeed, skill, "");
        m_skillMoveInfo.maxMoveDistance = maxDistance;
        m_skillMoveInfo.maxMoveTime = maxMoveTime;
        skill.RegistCB_SkillHarmTarget(OnSkillHarmTarget);
        obj.SetSkillMove(m_skillMoveInfo);
    }

    public override void Stop() {
        obj = null;
        skill.UnRegistCB_SkillHarmTarget(OnSkillHarmTarget);
    }

    public void OnSkillHarmTarget(SkillTL aSkill, Puppet target) {
        if(obj != null && skill.GetHarmObjsCount() >= maxHarmCount) {
            obj.ClearSkillMove();
            skill.UnRegistCB_SkillHarmTarget(OnSkillHarmTarget);
        }
    }


}

}
